// clang-format off

#include "amimagepreivew.h"
#include "qmessagebox.h"
#include "ui_amimagepreivew.h"

#include <QCursor>
#include <QScreen>

AmImagePreivew::AmImagePreivew(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AmImagePreivew)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_NativeWindow);
//    setAttribute(Qt::AA_EnableHighDpiScaling);
    setWindowFlags(windowFlags()| Qt::FramelessWindowHint);
}

AmImagePreivew::~AmImagePreivew()
{
    delete ui;
}

void AmImagePreivew::setPreviewImage(QPixmap picImage)
{
//    picImage.setDevicePixelRatio(QPaintDevice::devicePixelRatio());
    QScreen *screen = QGuiApplication::primaryScreen(); // 主屏幕

    // QString info = QString("h:%1, w:%2, dpr: %3, sdpr: %4, slen: %5")
    //                         .arg(picImage.height())
    //                         .arg(picImage.width()).arg(QPaintDevice::devicePixelRatio()).arg(screen->devicePixelRatio()).arg(QGuiApplication::screens().length());
    // QMessageBox::information(this, "", info);
//    ui->image->setPixmap(picImage.scaledToHeight(720, Qt::TransformationMode::SmoothTransformation));
    picImage.setDevicePixelRatio(screen->devicePixelRatio());
    ui->image->setPixmap(picImage);
}

void AmImagePreivew::mouseReleaseEvent(QMouseEvent *event)
{
    hide();
}
